<extend name="Public:mainbase" />
<block name="content">
    <link rel="stylesheet" href="http://g.alicdn.com/de/prismplayer/1.4.7/skins/default/index.css" />
    <script type="text/javascript" src="http://g.alicdn.com/de/prismplayer/1.4.7/prism-min.js"></script>
    <style>
        .player{float:left;margin:0 10px 10px 0}
    </style>
    <div class="topbtn">
        <ul>
            <li>直播标题：{$liveList[0]['title']}</li>
            <li>申请人：{$liveList[0]['realname']}</li>
            <eq  name="liveList[0]['v_status']" value="1">
                <li>直播人：{$liveList[0]['v_user_id']}</li>
            </eq>
            <li>地点：{$liveList[0]['address']}</li>
            <li>简介：{$liveList[0]['intro']}</li>
            <eq  name="liveList[0]['v_status']" value="3">
                <li>审核人：{$liveList[0]['v_user_id']}</li>
                <li>打回原因：{$liveList[0]['back_reason']}</li>
            </eq>
        </ul>
         <?php if($liveList[0]['v_status']==1 && $liveList[0]['group_stauts']!=3){ ?>
            <button type="button" class="streamAll <?php if($vo[0]['group_stauts']==0){ echo 'streamOn btn-warning';}else{echo 'streamOff btn-danger';} ?> btn  btn-sm" ><?php if($vo[0]['group_stauts']==0 || $vo[0]['group_stauts']==3){ echo '开启全部直播通道';}else{echo '关闭全部直播通道';} ?></button>
            <button type="button" class="<?php if($vo[0]['group_stauts']==1 || $vo[0]['group_stauts']==2){ echo 'streamOn btn-warning';}else{echo 'streamOff btn-danger';} ?> btn btn-sm"><?php if($vo[0]['group_stauts']==1 || $vo[0]['group_stauts']==2){ echo '全部直播开始';}else{echo '全部直播结束';} ?></button>
            <button type="button" class="btn btn-default btn-sm">获取播流地址</button>
         <?php } ?>
    </div>

    <volist name="liveList" id="vo">
        <div class="player">
            <div id="J_prismPlayer_{$vo.id}" class="prism-player"></div>
            <script>
                // 初始化播放器
                var player_{$vo.id} = new prismplayer({
                    id: "J_prismPlayer_{$vo.id}", // 容器id
                    source: '{:authAliyun("http://jwlive.appwuhan.com/jw/".$vo['group_id']."_".$vo['user_id'].".m3u8")}',// 视频地址
                    autoplay: true,    //自动播放：否
                    isLive:true,
                    width: "100%",       // 播放器宽度
                    height: "300px",      // 播放器高度
                    extraInfo:{
                        "fullTitle":"{$vo.title}-{$vo.realname}",                //全屏时显示视频标题(目前仅flash支持)；
                        "liveRetry":0                          //直播流中断是否重试；
                    }
                });

                player_{$vo.id}.on("ready",function(){
                    player_{$vo.id}.play();
                })
                // 监听播放器的pause事件
                player_{$vo.id}.on("liveStreamStop", function() {
                    var obj=this;
                    $.get('{:U("ajax_get_vstatus",array("id"=>$vo["id"]))}',function(data){
                        liveStatusAlert(obj,data,"{$vo.realname}");
                    })
                });
            </script>
            <div class="name text-center" data-id="{$vo.id}" data-stream="{$vo['group_id']}_{$vo['user_id']}">
                直播人：{$vo.realname}
                <span class="btns"></span>
            </div>
        </div>
    </volist>
    </div>

    <script>
        function liveStatusAlert(obj,data,info){
            if(data==0 || data==3){
                obj.pause();
                alert(info+"的直播已经停止！");
            }else if(data==1 || data==2){
                obj.play();
                alert(info+"的直播无信号！");
            }
        }

        $(".name").each(function(){
            $(this).find('.btns').load("{:U('showBTNs')}?id="+$(this).data('id'))
        })

        $('.name').on("click",'.stream',function(){
            var obj=this;
            var time=new Date();
            time=time.getTime();
            if($(obj).hasClass('streamOff')){
                $.get("{:U('ajaxStreamOff')}?liveId="+$(obj).parents('.name').data('id')+"&stream="+$(obj).parents('.name').data('stream'),function(data){
                    if(data.status==0){
                        $(obj).parents('.name').find('.btns').load("{:U('showBTNs')}?id="+$(obj).parents('.name').data('id')+"&ts="+time);
                        alert(data.msg);
                    }else{
                        alert(data.msg);
                    }
                })
            }else if($(obj).hasClass('streamOn')){
                $.get("{:U('ajaxStreamOn')}?liveId="+$(obj).parents('.name').data('id')+"&stream="+$(obj).parents('.name').data('stream'),function(data){
                    if(data.status==0){
                        $(obj).parents('.name').find('.btns').load("{:U('showBTNs')}?id="+$(obj).parents('.name').data('id')+"&ts="+time);
                        alert(data.msg);
                    }else{
                        alert(data.msg);
                    }
                })
            }
        })

        $('.name').on("click",'.live',function(){
            var obj=this;
            var time=new Date();
            time=time.getTime();
            if($(obj).hasClass('liveOff')){
                $.get("{:U('ajaxLiveOff')}?liveId="+$(obj).data('id')+"&stream="+$(obj.parents('.name')).data('stream'),function(data){
                    if(data.status==0){
                        $(obj).parents('.name').find('.btns').load("{:U('showBTNs')}?id="+$(obj).parents('.name').data('id')+"&ts="+time);
                    }
                     alert(data.msg);
                })
            }else if($(obj).hasClass('liveOn')){
                $.get("{:U('ajaxLiveOn')}?liveId="+$(obj).data('id')+"&stream="+$(obj).parents('.name').data('stream'),function(data){
                    if(data.status==0){
                        $(obj).parents('.name').find('.btns').load("{:U('showBTNs')}?id="+$(obj).parents('.name').data('id')+"&ts="+time);
                    }
                    alert(data.msg);
                })
            }
        })
    </script>
</block>